# Maintainer: Jan de Groot <jgc@archlinux.org>

pkgbase=dbus-python
pkgname=('python-dbus' 'python2-dbus' 'python-dbus-common')
pkgver=1.2.8
pkgrel=2
pkgdesc="Python bindings for DBUS"
url="https://www.freedesktop.org/wiki/Software/DBusBindings"
arch=(x86_64)
license=('GPL' 'LGPL')
depends=('dbus' 'glib2')
makedepends=('python' 'python2' 'autoconf-archive' 'python-sphinx_rtd_theme' 'python-sphinx')
source=(https://dbus.freedesktop.org/releases/${pkgbase}/${pkgbase}-${pkgver}.tar.gz{,.asc})
sha256sums=('abf12bbb765e300bf8e2a1b2f32f85949eab06998dbda127952c31cb63957b6f'
            'SKIP')
validpgpkeys=('DA98F25C0871C49A59EAFF2C4DE8FF2A63C7CC90')

prepare() {
  mkdir build-python2 build-python3
  cd $pkgbase-$pkgver
  autoreconf -fi
}

build() {
  cd build-python2
  ../${pkgbase}-${pkgver}/configure --prefix=/usr PYTHON_VERSION=2
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make

  cd ../build-python3
  ../${pkgbase}-${pkgver}/configure --prefix=/usr
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

package_python-dbus-common() {
  pkgdesc="Common dbus-python files shared between python-dbus and python2-dbus"
  depends=()
  conflicts=('dbus-python<1.1.0')

  cd build-python3
  make DESTDIR="${pkgdir}" install-data
  rm -r "${pkgdir}"/usr/lib/python*
}

package_python-dbus() {
  depends+=('python-dbus-common' 'python')
  pkgdesc="Python bindings for DBUS"

  cd build-python3
  make DESTDIR="${pkgdir}" install

  rm -rf "${pkgdir}/usr/share"
  rm -r "${pkgdir}/usr/include"
  rm -r "${pkgdir}/usr/lib/pkgconfig"
}

package_python2-dbus() {
  depends+=('python-dbus-common' 'python2')
  pkgdesc="Python2 bindings for DBUS"
  replaces=('dbus-python')
  conflicts=('dbus-python')
  provides=("dbus-python=$pkgver")

  cd build-python2
  make DESTDIR="${pkgdir}" install

  rm -rf "${pkgdir}/usr/share"
  rm -r "${pkgdir}/usr/include"
  rm -r "${pkgdir}/usr/lib/pkgconfig"
}
